package com.github.cooingandwooing.uaa.config;

import java.security.KeyPair;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.security.oauth2.provider.token.store.KeyStoreKeyFactory;

@Configuration
public class KeyPairConfig {

    /**
     * keytool -genkeypair -alias cdw-oauth-jwt -keyalg RSA -keypass 123cm456 -keystore cdw-jwt.jks -storepass 123cm456
     * @return
     * @throws Exception
     */
    @Bean
    public KeyPair keyPair() throws Exception {
        ClassPathResource ksFile = new ClassPathResource("cdw-jwt.jks");
        KeyStoreKeyFactory ksFactory = new KeyStoreKeyFactory(ksFile, "123cm456".toCharArray());
        return ksFactory.getKeyPair("cdw-oauth-jwt");
    }
}
